package com.openbravo.data.loader;

import java.util.Date;

import com.openbravo.data.basic.BasicException;

public class DataReadWare implements DataRead {

	DataRead dataRead;
	int key;
	int start;
	
	@Override
	public Integer getInt(int columnIndex) throws BasicException {
		
		int realColumnIndex=columnIndex;
		if(columnIndex>=key)
			realColumnIndex+=start;
		return dataRead.getInt(realColumnIndex);
	}

	@Override
	public String getString(int columnIndex) throws BasicException {
		int realColumnIndex=columnIndex;
		if(columnIndex>=key)
			realColumnIndex+=start;
		return dataRead.getString(realColumnIndex);
	}

	@Override
	public Double getDouble(int columnIndex) throws BasicException {
		int realColumnIndex=columnIndex;
		if(columnIndex>=key)
			realColumnIndex+=start;
		return dataRead.getDouble(realColumnIndex);
	}

	@Override
	public Boolean getBoolean(int columnIndex) throws BasicException {
		int realColumnIndex=columnIndex;
		if(columnIndex>=key)
			realColumnIndex+=start;
		return dataRead.getBoolean(realColumnIndex);
	}

	@Override
	public Date getTimestamp(int columnIndex) throws BasicException {
		int realColumnIndex=columnIndex;
		if(columnIndex>=key)
			realColumnIndex+=start;
		return dataRead.getTimestamp(realColumnIndex);
	}

	@Override
	public byte[] getBytes(int columnIndex) throws BasicException {
		int realColumnIndex=columnIndex;
		if(columnIndex>=key)
			realColumnIndex+=start;
		return dataRead.getBytes(realColumnIndex);
	}

	@Override
	public Object getObject(int columnIndex) throws BasicException {
		int realColumnIndex=columnIndex;
		if(columnIndex>=key)
			realColumnIndex+=start;
		return dataRead.getObject(realColumnIndex);
	}

	@Override
	public DataField[] getDataField() throws BasicException {
		int x=dataRead.getDataField().length-start+key;
		DataField[] superDataField=dataRead.getDataField();
		DataField[] dataField=new DataField[x];
		for(int i=0;i<x;i++)
			if(i>=key)
				dataField[i]=superDataField[i+start];
			else 
				dataField[i]=superDataField[i];
		return dataField;
	}

	@Override
	public long getLong(int columnIndex) throws BasicException {
		int realColumnIndex=columnIndex;
		if(columnIndex>=key)
			realColumnIndex+=start;
		return dataRead.getLong(realColumnIndex);
	}

}
